<div id="box01" style="padding-left:5px; padding-right:10px; width:500px;">  
<div id=""> 请选择下列描述中最接近的一项 ：</div><br />
  <% form_for(:test, :url => { :action => "result" } ,
    :html => {:name=>'testQuestionForm', :id=>'testQuestionForm', :onsubmit=>'return t_checkform(this);' }) do |f|%>
  <%= error_messages_for :test %>
    <center><!--测试图片和说明显示部分-->
    <table class="dashed_1211" width="96%" border="0" cellpadding="3" cellspacing="0"> <tbody></tbody>
    </table>
    <table class="top10" width="96%" border="0" cellpadding="10" cellspacing="0">
      <tbody><tr>
         <td valign="top" width="160" height="163">
        	<img src="/lanxin/a_data/1247653857031.jpg" class="img4" width="144" height="144">
         </td>
         <td valign="top">
            <table width="96%" border="0" cellpadding="5" cellspacing="0">
              <tbody> <tr>
                <td class="cs_jiesho_1211">
                  <%= @test.title %><br/>
                  <%= @test.description %>
                </td></tr>
           </tbody></table>
         </td></tr></tbody>
    </table><div>
     <input type="hidden" name="test_id" value=<%=@test.id%> />
                    <% if current_user.tested?(Survey.find(@test.id)) %>
                  <input type="hidden" name="re_test" value="yes"/>
                     <% end %>
   </div>
   </center>

  <!--测试题目显示部分-->
  <div class="border1_1211 top20">
      <% i = 1%>
      <% @test.questions.each do |question| %>
   <table width="100%" border="0" cellpadding="13" cellspacing="0">
              <tbody><tr>
            <td class="cs_title_1211" align="left">
            <a name="position_6287">
         第&nbsp;<%=i%>&nbsp;题 ：<%= question.description%></a>
             <input  id="question<%=question.id%>" class="question-values"name="question<%=question.id%>[value]" value="-255" type="hidden"/>
            </td>
        </tr>
        <tr>      
          <td align="center">
            <table width="96%" border="0" cellpadding="13" cellspacing="0">
                <tbody>
                <% @test.choices.each do |choice|%>
                <tr style="cursor: pointer;" onmousemove="this.bgColor='#F4F4F4'" onmouseout="this.bgColor=''" bgcolor="">
                    <td class="cs_daan_1211" onclick="t_nextItem(<%=question.id%>,<%=choice.id%>);" width="20">
                    <input id="answervalue_<%=choice.id%>" name="question<%=question.id%>[choice][value]" value="<%=choice.value%>" type="hidden">
                    <img src="/images/user/test/choose3.gif" id="question<%=question.id%>[choice<%=choice.id%>]"></td>
                    <td class="cs_daan_1211" onclick="t_nextItem(<%=question.id%>,<%=choice.id%>);" width="20" >
                        <%= choice.content %>
                    </td>
                </tr>					
                <% end %>
            </tbody></table>
            </td>
    
         </td> </tr>
    </tbody></table>
      <% i = i +1%>
      <% end %>
      <center>
      <input type="submit" name="" value="完成" > 
      </center>
</div>

<% end %>
</div>

<script type="text/javascript">
  
  function t_checkform(thisform) {
  var values = thisform.getElementsByClassName("question-values");
          for(var i=0; i<values.length; i++)
          {
              if(values[i].value == "-255") 
              {
              alert("您的题还没有做完。");
                return false;
              }
          }
          return true;
  }

  
function t_nextItem(question_id,imgId){
	if(imgId==0)return false;
	var answerObj = document.getElementById(imgId);
	var answer = document.getElementById("question"+question_id);
	var value = document.getElementById("answervalue_"+imgId).value;
	//给选择的答案赋值
	answer.value = value;
	//取消原来选中的                       
	var answerObjs = document.forms["testQuestionForm"].elements["question"+question_id+"[choice][value]"];
	for(var i=0;i<answerObjs.length;i++){
		  var id = answerObjs[i].id;
		  var arr=id.split("_");
	  	id=arr[1]//id.substring(id.indexOf("_")+1);
	  	var i_id="question"+question_id+"[choice"+id+"]";
	  	document.getElementById(i_id).src="/images/user/test/choose3.gif";
	}
	//换图片
	var imgObj_id="question"+question_id+"[choice"+imgId+"]";
	var q_answerObj=document.getElementById(imgObj_id);
	q_answerObj.src="/images/user/test/choose4.gif";
	tmpAnswer = answerObj;
  
}
</script>
